package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Slf4j
@Component
public class OrderTask {
    @Autowired
    private OrderMapper orderMapper;
    //@Scheduled(cron = "0 0/15 * * * * ?")
    public void processTimeoutOrder(){
        log.info("处理支付超时订单：{}", new Date());
        List<Long> ids = orderMapper.select(LocalDateTime.now().minusMinutes(15));
        Orders orders = Orders.builder().
                status(Orders.CANCELLED).
                cancelTime(LocalDateTime.now()).
                build();
        int count = orderMapper.update(orders,ids);
        log.info("处理支付超时订单：{}笔", count);
    }
    //@Scheduled(cron = "0 0 * * * * ?")
    public void processDeliveryOrder(){
        log.info("处理派送中订单：{}", new Date());
        List<Long> ids = orderMapper.select(LocalDateTime.now().minusDays(1));
        Orders orders = Orders.builder().
                status(Orders.COMPLETED).
                build();
        int count = orderMapper.update(orders,ids);
        log.info("处理派送中订单：{}笔", count);

    }
}
